﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace fhe
{
  using math;
  using physics;
  using core;
  namespace test
  {
    class Program
    {
      private static void Assert(bool cond)
      {
        if (!cond)
        {
          throw new Exception();
        }
      }

      private static void CheckOffset(Body body, Vec2 expectedOffset, Vec2 v)
      {
        Assert(body.Inside(v));
        Vec2 offset;
        List<PointMass> points;
        body.OffsetTo(v, null, out offset, out points);
        Assert(expectedOffset == offset);
      }

      static void Main(string[] args)
      {
        Body rect = Body.Rectangle(new Vec2(0, 0), new Vec2(1, 1));
        Assert(!rect.Inside(new Vec2(1.5, 0.5)));
        CheckOffset(rect, new Vec2(-0.1, 0), new Vec2(0.1, 0.5));
        CheckOffset(rect, new Vec2(0, 0.1), new Vec2(0.5, 0.9));
        CheckOffset(rect, new Vec2(0, -0.1), new Vec2(0.2, 0.1));

        new Sim()
        {
          Children = new List<Node>()
          {
            new World()
            {
              Children = new List<Node>()
              {
                Body.Rectangle(new Vec2(-100,-1), new Vec2(100,0),0),
                Body.Rectangle(new Vec2(-0.5,4), new Vec2(0.5,5)),
              },
            },
          },
        }.Run(TimeSpan.FromSeconds(0.01), TimeSpan.FromSeconds(10));
      }
    }
  }
}
